//
//  OJStatus.m
//  openJira
//
//  Created by Vincent Demay on 30/04/10.
//  Copyright 2010 Goojet. All rights reserved.
//

#import "OJStatus.h"


@implementation OJStatus

@synthesize name, description, lid, icon;


- (void) dealloc {
	[name release];
	[description release];
	[icon release];
	[super dealloc];
}


@end



///////////////////////// OJISSUELIST //////////////////////

@implementation OJStatusList

@synthesize statuses, delegate;

- (id) init {
	self = [super init];
	if (self != nil) {
	}
	return self;
}


- (void) getStatuses{
	[[OJConnector getDefault] getStatuses:self];
}


////////////////////////// MANAGE RESPONSES ///////////////////
- (void) request:(XMLRPCRequest *)request onResponseSuccessfull:(XMLRPCResponse*) response{
	id fromResponse = [response  object];
	[statuses release];
	statuses = [[NSMutableDictionary alloc] init];
	
	for (int i=0; i<[fromResponse count]; i++) {
		OJStatus *oneStatus = [[OJStatus alloc] init];
		oneStatus.name = [((NSDictionary*)[fromResponse objectAtIndex:i]) objectForKey:@"name"];
		oneStatus.description = [((NSDictionary*)[fromResponse objectAtIndex:i]) objectForKey:@"description"];
		oneStatus.icon = [((NSDictionary*)[fromResponse objectAtIndex:i]) objectForKey:@"icon"];
		oneStatus.lid = [[((NSDictionary*)[fromResponse objectAtIndex:i]) objectForKey:@"id"] intValue];
		[statuses setObject:oneStatus forKey:[NSString stringWithFormat:@"%d",oneStatus.lid]];
		[oneStatus release];
	}
	
	[delegate object:self isReady:NO];
}

- (void) request:(XMLRPCRequest *)request onResponseError:(XMLRPCResponse*) response{
	[delegate object:self isReady:YES];
}


@end
